package com.xcity.game.item.effect;

import java.util.Collection;

import com.xcity.db.entity.Employee;
import com.xcity.db.entity.Player;
import com.xcity.game.common.Cause;
import com.xcity.game.common.MessageConst;
import com.xcity.game.item.GameItem;
import com.xcity.game.item.ItemEffect;
import com.xcity.game.item.ItemException;
import com.xcity.game.item.listener.BagListener;

/**
 * 增加员工经验
 * @author yang.li
 *
 */
public class AddEmployeeExpEffect implements ItemEffect {

	@Override
	public boolean effect(Player player, GameItem item, int count, BagListener listener) throws ItemException {
		int[] params = item.getTemplate().getParams();
		if (params != null && params.length > 0) {
			Collection<Employee> employees = player.getEmployees().getEmployees();
			if (employees == null || employees.isEmpty()) {
				throw new ItemException(MessageConst.EMPLOYEE_HAVE_NO);
			}
			boolean succ = employees.iterator().next().addExp(params[0] * count, Cause.USE_ITEM);
			if (succ) {
				return true;
			}
			throw new ItemException(MessageConst.EMPLOYEE_TRAIN_LEVEL_MAX);
		}
		return false;
	}

}
